//
//  LBHomeViewController.m
//  LBUIKit_Example
//
//  Created by LINAICAI on 2017/9/27.
//  Copyright © 2017年 李柰财. All rights reserved.
//

#import "LBHomeViewController.h"
#import <LBNavigationController.h>
#import <UINavigationController+LBNavigationBar.h>
#import <UINavigationController+LBFindViewController.h>
#import <LBTipsView.h>
#import <LBBannerTipsView.h>
#import <Masonry/Masonry.h>
#import <LBCellBuilder.h>
#import <LBCellItemBuilder.h>
#import "LBWebViewController.h"
#import <LBLoadingFullView.h>
#import <LBLoadingView.h>
#import <LBUIKit/LBCalendarPickerView.h>
#import <LBUIKit/LBCalendarContentView.h>
#import <LBCategory/NSString+LBDate.h>
#import <LBTokenStore.h>
#import "LBContainViewController.h"
static NSString *const cellID = @"identity";
@interface LBHomeViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic , strong)UITableView *tableView;
@property(nonatomic , strong)NSArray<LBCellItemBuilder *> *dataSouces;
@end

@implementation LBHomeViewController
- (NSArray<LBCellItemBuilder *> *)dataSouces{
    if (!_dataSouces) {
        __block LBCellItemBuilder *item = [[LBCellItemBuilder alloc]initWithTitle:@"没JS交互" style:LBCellItemBuilderStyleArrow action:^{
            
            LBWebViewController *vc = [[LBWebViewController alloc]initTitle:@"联结平台在线承包管理协议" url:@"https://www.lianj.com/"];
            [self.navigationController pushViewController:vc animated:YES];
        }];
        __block LBCellItemBuilder *item1 = [[LBCellItemBuilder alloc]initWithTitle:@"有JS交互的" style:LBCellItemBuilderStyleArrow action:^{
            LBContainViewController *vc = [[LBContainViewController alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
            
            
        }];
        __block LBCellItemBuilder *item2 = [[LBCellItemBuilder alloc]initWithTitle:@"LBLoadingFullView加载中的样式" style:LBCellItemBuilderStyleArrow action:^{
            [LBLoadingView showInView:self.view];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [LBLoadingView dismiss];
                LBLoadingFullView *loadingView = [[LBLoadingFullView alloc]initWithStyle:LBLoadingTipsViewLoading];
                [loadingView showInView:self.view];
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [loadingView dismiss];
                });
            });
            
            
        }];
        __block LBCellItemBuilder *item3 = [[LBCellItemBuilder alloc]initWithTitle:@"LBLoadingFullView加载失败的样式" style:LBCellItemBuilderStyleArrow action:^{
            [LBLoadingView showInView:self.view];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [LBLoadingView dismiss];
                LBLoadingFullView *loadingView = [[LBLoadingFullView alloc]initWithStyle:LBLoadingTipsViewError retry:^(LBLoadingFullView *loadingView) {
                    //点击了刷新
                    [LBLoadingView showInView:self.view];
                    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                        [LBLoadingView dismiss];
                    });
                }];
                [loadingView showInView:self.view];
                
            });
            
            
        }];
        _dataSouces = @[item,item1,item2,item3];
    }
    return _dataSouces;
}
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        [_tableView registerClass:LBCellBuilder.class forCellReuseIdentifier:cellID];
    }
    return _tableView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"Demo";
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets = UIEdgeInsetsZero;
    }];

//    [LBCalendarPickerView showWithFormat:@"yyyy-MM-dd" result:^(NSString *timeStamp, NSString *timeStr) {
//
//    }];
    
//    LBCalendarContentView *view = [[LBCalendarContentView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, [LBCalendarContentView viewHight]) type:LBCalendarPickerNoSelectLastAndTodayDate];
//    view.monthButtonClick = ^(NSString *timeStamp, NSUInteger dayNum) {
//
//        NSTimeInterval interval = [timeStamp doubleValue] + NSStringDateTimeDAY * dayNum *1000 - 1;
//
//    };
//    view.select = ^(NSString *timeStamp, NSString *timeStr) {
//
//    };
//    [self.view addSubview:view];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    LBCellBuilder *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
    LBCellItemBuilder *item = self.dataSouces[indexPath.row];
    [cell setItem:item];
    return cell;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSouces.count;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    LBCellItemBuilder *item = self.dataSouces[indexPath.row];
    if (item.action) {
        item.action();
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return CGFLOAT_MIN;
}

@end
